package org.jiangy.authentication.web;

import org.jiangy.Constants;
import org.jiangy.notification.AliyunSmsMsgSender;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>创建时间: 2024/8/14 </p>
 *
 * @author <a href="mailto:jiangliu0316@outlook.com" rel="nofollow">蒋勇</a>
 */
@RestController
@RequestMapping("/auth/otp")
public class OtpController {

    private final RedisTemplate<String, String> redisTemplate;

    public OtpController(RedisTemplate<String, String> redisTemplate) {
        this.redisTemplate = redisTemplate;
    }

    @PostMapping("sms")
    public String sendSms() {
        String code = AliyunSmsMsgSender.send();
        // sms code 入 redis
        redisTemplate.opsForValue().set(Constants.BJQ_SIGNUP_SMS_CODE, code);
        return code;
    }
}
